//
//  BaseTableViewController.m
//  20240823
//
//  Created by 张伟 on 2024/8/25.
//

#import "BaseTableViewController.h"

@interface BaseTableViewController ()

@property (nonatomic) MJRefreshNormalHeader * refreshHeader;
@property (nonatomic) MJRefreshAutoFooter * refreshFooter;

@end

@implementation BaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.page = 0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

- (void)addRefreshHeader {
    MJWeakSelf
    _refreshHeader = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf refreshAction];
    }];
    self.tableView.mj_header = _refreshHeader;
}

- (void)addRefreshFooter {
    MJWeakSelf
    _refreshFooter = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        [weakSelf loadMoreAction];
    }];
    self.tableView.mj_footer = _refreshFooter;
}

- (void)addRefreshHeaderAndFooter {
    
    MJWeakSelf
    _refreshHeader = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf refreshAction];
    }];
    self.tableView.mj_header = _refreshHeader;
    
    _refreshFooter = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        [weakSelf loadMoreAction];
    }];
    self.tableView.mj_footer = _refreshFooter;
}

- (void)refreshAction {

}

- (void)loadMoreAction {

}

-(void)endRefresh{
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCell.new;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = NSMutableArray.array;
    }
    return _dataSource;
}

- (NSInteger)pageSize {
    return 10;
}

@end
